<?php

class Backoffice_Model_FormUser extends CC_Backoffice_Form
{
    public function __construct($options = null)
    {
        parent::__construct($options);
        $_em = Zend_Registry::getInstance()->get('doctrine')->getEntityManager();
        
        $firstname = new Zend_Form_Element_Text('firstname');
        $firstname->setAttrib('size', 28)
                  ->setLabel("Firstname")
                  ->setRequired(true)
                  ->addErrorMessage("A first name is required");

        $initials = new Zend_Form_Element_Text('initials');
        $initials->setAttrib('size', 28)
                ->setLabel("Initials");
                
        $surname = new Zend_Form_Element_Text('surname');
        $surname->setAttrib('size', 28)
                ->setLabel("Surname")
                ->setRequired(true)
                ->addErrorMessage("A surname is required");

        $contactNumber = new Zend_Form_Element_Text('contactNumber');
        $contactNumber->setAttrib('size', 28)
                      ->setLabel("Contact Number");

        $provider = new CC_Form_ProviderDropdown('provider', $_em);
        $provider->setLabel("Provider")
                 ->setRequired(true)
                 ->addErrorMessage("A provider needs to be selected");
        
        $groups = new CC_Form_GroupMultiCheckbox('groups', $_em);

        $email = new Zend_Form_Element_Text('email');
        $email->setAttrib('size', 28)
              ->setLabel("Email")
              ->setRequired(true)
              ->addValidator('emailAddress')
              ->addErrorMessage("A valid email address is required");
              
        $signature = new Zend_Form_Element_Textarea('signature');
        $signature->setLabel("Signature")
                  ->setAttrib('rows', 5);
              
        $username = new Zend_Form_Element_Text('username');
        $username->setAttrib('size', 28)
                 ->setLabel("Username")
                 ->setRequired(true)
                 ->addErrorMessage("A Username is required and can't be empty");

        $password = new Zend_Form_Element_Password('password');
        $password->setAttrib('size', 28)
                 ->setLabel("Password")
                 ->setRequired(true)
                 ->addErrorMessage("A password is required and can't be empty");

        $confirmPassword = new Zend_Form_Element_Password('confirmPassword');
        $confirmPassword->setAttrib('size', 28)
                        ->setLabel("Confrim Password")
                        ->setRequired(true)
                        ->addValidator('Identical', false, array('token' => 'password'))
                        ->addErrorMessage("The passwords do not match");

        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel("Create User");

        $this->addElements(array($firstname, $initials, $surname, $email, $username, $password, $confirmPassword, $contactNumber,  $provider, $signature, $groups, $submit));
        
        // Add elements to display group to make it look neat
        $this->addDisplayGroup(array(
            'firstname',
            'initials',
            'surname',
            'contactNumber'
        ), 'contacts', array('legend' => 'Contact Information'));
        
        $this->addDisplayGroup(array(
            'email',
            'username',
            'provider',
            'signature'
        ), 'account', array('legend' => 'Account Information'));
        
        $this->addDisplayGroup(array(
            'password',
            'confirmPassword'
        ), 'passwords', array('legend' => 'Password'));
        
        $this->addDisplayGroup(array(
            'groups'
        ), 'access', array('legend' => 'Groups'));
        
        $this->addDisplayGroup(array(
            'submit'
        ), 'submit');
    }

}
              